﻿using FSUIPC;
using SimWithP3d.Vehicle;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace SimWithP3d.ViewModel
{
    public class MotionPlatformViewModel : NotifyChanged
    {
        public static Offset<int> Pitch_Angle = new Offset<int>("MotionPlatform", 0x0578, false);   // 俯仰角 PLANE PITCH DEGREES     Radians        //*360/(65536*65536)   dgree    下加上减  左加右减
        public static Offset<int> Bank_Angle = new Offset<int>("MotionPlatform", 0x057C, false);//倾斜角 PLANE BANK DEGREES      Radians 
        public static Offset<uint> Heading_Angle = new Offset<uint>("MotionPlatform", 0x0580, false);//相对正北方向 PLANE HEADING DEGREES TRUE    Radians

        public static Offset<double> RollVel = new Offset<double>("MotionPlatform", 0x30B0);//ROTATION VELOCITY BODY X 
        public static Offset<double> PitchVel = new Offset<double>("MotionPlatform", 0x30A8); //ROTATION VELOCITY BODY Y  Feet per second       //rads/sec
        public static Offset<double> YawVel = new Offset<double>("MotionPlatform", 0x30B8);//ROTATION VELOCITY BODY Z 

        public static Offset<double> XAcc = new Offset<double>("MotionPlatform", 0x3060);  //ACCELERATION BODY X  Feet per second squared    //ft/sec/sec
        public static Offset<double> YAcc = new Offset<double>("MotionPlatform", 0x3068);//ACCELERATION BODY Y 
        public static Offset<double> ZAcc = new Offset<double>("MotionPlatform", 0x3070);// ACCELERATION BODY Z 

        public static Offset<double> PitchAcc = new Offset<double>("MotionPlatform", 0x3078, false);     //radians/sec/sec
        public static Offset<double> RollAcc = new Offset<double>("MotionPlatform", 0x3080, false);
        public static Offset<double> YawAcc = new Offset<double>("MotionPlatform", 0x3088, false);

        private float xa;
        private float ya;
        private float za;
        private float xrV;
        private float yrV;
        private float zrV;
        private float xr;
        private float yr;
        private float zr;

        public float Xa
        {
            get { return xa; }
            set { xa = value; OnPropertyChanged(new PropertyChangedEventArgs("Xa")); }
        }
        public float Ya
        {
            get { return ya; }
            set { ya = value; OnPropertyChanged(new PropertyChangedEventArgs("Ya")); }
        }
        public float Za
        {
            get { return za; }
            set { za = value; OnPropertyChanged(new PropertyChangedEventArgs("Za")); }
        }
        public float XrV
        {
            get { return xrV; }
            set { xrV = value; OnPropertyChanged(new PropertyChangedEventArgs("XrV")); }
        }
        public float YrV
        {
            get { return yrV; }
            set { yrV = value; OnPropertyChanged(new PropertyChangedEventArgs("YrV")); }
        }
        public float ZrV
        {
            get { return zrV; }
            set { zrV = value; OnPropertyChanged(new PropertyChangedEventArgs("ZrV")); }
        }
        public float Xr
        {
            get { return xr; }
            set { xr = value; OnPropertyChanged(new PropertyChangedEventArgs("Xr")); }
        }
        public float Yr
        {
            get { return yr; }
            set { yr = value; OnPropertyChanged(new PropertyChangedEventArgs("Yr")); }
        }
        public float Zr
        {
            get { return zr; }
            set { zr = value; OnPropertyChanged(new PropertyChangedEventArgs("Zr")); }
        }
        public MotionPlatformViewModel()
        {
            timer = new System.Timers.Timer();
            timer.Interval = 40;
            timer.Elapsed += Timer_Elapsed;
            timer.Start();
        }
        ~MotionPlatformViewModel()
        {
            timer.Stop();
            timer.Dispose();
        }
        private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Xa = Convert.ToSingle(XAcc.Value);
            Ya = Convert.ToSingle(YAcc.Value);
            Za = Convert.ToSingle(ZAcc.Value);

            XrV = Convert.ToSingle(RollVel.Value);
            YrV = Convert.ToSingle(PitchVel.Value);
            ZrV = Convert.ToSingle(YawVel.Value);

            Xr = Convert.ToSingle(Pitch_Angle.Value * 360.0 / 65536.0 / 65536.0 * (Math.PI / 180));
            Yr = Convert.ToSingle(Bank_Angle.Value * 360.0 / 65536.0 / 65536.0 * (Math.PI / 180));
            Zr = Convert.ToSingle(Heading_Angle.Value * 360.0 / 65536.0 / 65536.0 * (Math.PI / 180));
        }
        System.Timers.Timer timer;
    }
}
